package com.freewater.springboot.demo.ioc.qualifier.customqualifier;

import com.freewater.springboot.demo.PackageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;

/**
 * 自定义Qualifier
 */
@Slf4j
public class Main {

    public static void main(String[] args) {
        GenericApplicationContext applicationContext = new GenericApplicationContext();
        final String xmlPath = PackageUtils.getDefaultAppContextXmlPath(Main.class);
        new XmlBeanDefinitionReader(applicationContext).loadBeanDefinitions(xmlPath);
        applicationContext.refresh();
        log.info("使用ApplicationContext：{}", xmlPath);
        applicationContext.start();
        applicationContext.registerShutdownHook(); // 注册jvm关闭回调，jvm关闭时一并关闭spring容器
        final MovieRecommender movieRecommender = applicationContext.getBean(MovieRecommender.class);
        System.out.println(movieRecommender.getActionVhsCatalog().getBeanName());
        System.out.println(movieRecommender.getComedyVhsCatalog().getBeanName());
        System.out.println(movieRecommender.getActionDvdCatalog().getBeanName());
        System.out.println(movieRecommender.getComedyBluRayCatalog().getBeanName());
    }
}
